package com.zsck.pos.activity;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.ums.AppHelper;
import com.ums.anypay.service.IOnTransEndListener;
import com.chinaums.commoncheck.R;
import com.zsck.pos.base.BaseTitleActivity;
import com.zsck.pos.bean.PaySuccess;
import com.zsck.pos.common.ActivityManager;
import com.zsck.pos.common.Constants;
import com.zsck.pos.net.MyObserver;
import com.zsck.pos.utils.LogUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SuccessActivity extends BaseTitleActivity {

    /*去支付*/
    @BindView(R.id.tv_confirm)
    TextView mTvConfirm;
    /*房号*/
    @BindView(R.id.tv_room_num)
    TextView mTvRoomNum;
    /*账单周期*/
    @BindView(R.id.tv_billing_cycle)
    TextView mTvBillingCycle;
    /*支付时间*/
    @BindView(R.id.tv_pay_time)
    TextView mTvPayTime;
    /*支付方式*/
    @BindView(R.id.tv_pay_type)
    TextView mTvPayType;
    /*支付单号*/
    @BindView(R.id.tv_order_id)
    TextView mTvOrderId;

    private String mBillIdList;

    private PaySuccess mPayData;
    private String feel;
    private ComponentName componentName;

    @Override
    public int setLayout() {
        return R.layout.activity_success;
    }

    @Override
    public String setTitle() {
        return "支付";
    }

    @Override
    public Activity setActivity() {
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        initEvents();
        initData();
    }


    private void initEvents(){
        mTvConfirm.setOnClickListener(this);
    }
    private void initData(){
        Intent intent = getIntent();
        Object object = intent.getSerializableExtra("payData");
        if(!(object instanceof PaySuccess)){
            return;
        }
        feel = intent.getStringExtra("feeList");
        mPayData = (PaySuccess) object;
        mTvRoomNum.setText(mPayData.getRoomName());
        mTvBillingCycle.setText(mPayData.getBeginDate() + "-" + mPayData.getEndDate());
        mTvPayTime.setText(mPayData.getPayTime());
        if(!TextUtils.isEmpty(mPayData.getPaymentMethod())){
            mTvPayType.setText(mPayData.getPaymentMethod().replace("iPosCardPay","刷卡支付").replace("iPosQrCodePay","二维码支付"));
        }
        mTvOrderId.setText(mPayData.getTradeNo());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case  R.id.tv_confirm:
            case R.id.rl_back:
                if(TextUtils.equals("1",feel)){
                    componentName = new ComponentName("com.ums.sz.pos","com.zsck.pos.activity.BillsActivity");
                }else{
                    componentName= new ComponentName("com.ums.sz.pos","com.zsck.pos.activity.MultiBillsActivity");
                }
                Intent intent = new Intent();

                intent.setComponent(componentName);
                startActivity(intent);
                finish();
                break;
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        Intent intent = new Intent();
        if(TextUtils.equals("1",feel)){
            componentName = new ComponentName("com.ums.sz.pos","com.zsck.pos.activity.BillsActivity");
        }else{
            componentName= new ComponentName("com.ums.sz.pos","com.zsck.pos.activity.MultiBillsActivity");
        }
        intent.setComponent(componentName);
        startActivity(intent);
        finish();
    }
}
